const path = require('path');   
const HTtmlWebpackPlugin = require('html-webpack-plugin');
const { CleanWebpackPlugin } = require('clean-webpack-plugin');
const UglifyjsWebpackPlugin = require('uglifyjs-webpack-plugin');
const UglifyJS = require('uglify-es');

const DefaultUglifyJsOptions = UglifyJS.default_options();
const compress = DefaultUglifyJsOptions.compress;
for(let compressOption in compress) {
    compress[compressOption] = false;
}
compress.unused = true;

module.exports = {
  mode: 'production',
  // mode: 'development',
  // devtool: 'cheap-module-eval-source-map',
  entry: {
    main: './esmodule/index.js'
  },
  output: {
    filename: 'bundle.js',
    path: path.resolve(__dirname, './esmodule/dist')   // __dirname是配置文件所在目录
  },
  devServer: {
    contentBase: "./esmodule/dist",
    // open: true,
    hot: true,
    hotOnly: true
  },
  module: {
    rules: [
      {
        test: /\.css$/,
        use: [
          'style-loader', 
          'css-loader',
          'postcss-loader',
        ]
      },
      {
        test: /\.js$/,
        exclude: '/node_modules/',
        loader: 'babel-loader'
      }
    ]
  },

  plugins: [
    new CleanWebpackPlugin(),
    new HTtmlWebpackPlugin({
      template: './esmodule/index.html'
    })
  ],
  optimization: {
    usedExports: true
  },
}